<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订单列表</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/animate.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/style.min.css?v=4.1.0" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>订单列表</h5>
        </div>
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <div class="example-wrap">
                        <!-- start toolbar -->
                        <div class="col-sm-12">
                            <form class="form-horizontal" role="form" id="queryManifestForm">
                                <div class="row">
                                 	<div class="col-sm-4">
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">货单号</label>
                                            <div class="col-sm-8">
                                                <input type="text" class="form-control" placeholder="货单号"  id="manifestNum" name="manifestNum">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-4">
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">是否提单</label>
                                            <div class="col-sm-8">
                                                <select id="manifestIsTake" name="manifestIsTake" class="form-control">
                                                    <option value="">-----请选择-----</option>
                                                    <option value="0">-----未提单-----</option>
                                                    <option value="1">-----已提单-----</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-4">
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">是否回执</label>
                                            <div class="col-sm-8">
                                                <select id="manifestIsReturn" name="manifestIsReturn" class="form-control">
                                                    <option value="">-----请选择-----</option>
                                                    <option value="0">-----未回执-----</option>
                                                    <option value="1">-----已回执-----</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-12" style="text-align:center;">
                                    	<button type="button" class="btn btn-primary" id="queryManifestBtn">
                                            <span class="glyphicon glyphicon-search" aria-hidden="true"></span> 查询
                                        </button>
                                        <shiro:hasPermission name="create:order">
                                        <button class="btn btn-info" id="addBut" type="button">新增货单</button>
                                        </shiro:hasPermission>
                                        <button type="button" class="btn btn-info" id="" onclick="location.reload();">
                                            <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> 刷新
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <!-- end toolbar -->
                        <div class="example">
                            <table id="manifestTab" class="table" data-click-to-select="true" data-mobile-responsive="true">
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Panel Other -->
<script src="${pageContext.request.contextPath}/js/jquery.min.js?v=2.1.4"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${pageContext.request.contextPath}/js/content.min.js?v=1.0.0"></script>
<script src="${pageContext.request.contextPath}/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="${pageContext.request.contextPath}/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="${pageContext.request.contextPath}/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="${pageContext.request.contextPath}/js/plugins/layer/layer.min.js"></script>
<script src="${pageContext.request.contextPath}/laydate/laydate.js"></script>
<%-- <script src="${pageContext.request.contextPath}/js/business/manifest/manifest_list.js"></script> --%>
<script src="${pageContext.request.contextPath}/js/public/ttbj-core.js"></script>

<script type="text/javascript">
var $table = $("#manifestTab");
$(function () {
    initTable();
    //查询事件
    $("#queryManifestBtn").click(function () {
        $table.bootstrapTable('refresh');
    });
    
    //增加按钮
    $("#addBut").click(function () {
    	editManifestInfo(null);
    });
   
});

function initTable() {
    $table.bootstrapTable({
        dataType: "json",
        showColumns: true, 
        pagination: true, //分页
        striped: true,
        cache: false,	//是否使用缓存，默认是true
        pageSize: 10,
        pageNumber: 1,
        queryParamsType: 'limit',
        smartDisplay: true,
        sidePagination: "server",
        method: "post",	//使用post提交
        queryParams: queryParams,
        url: '../manifest/getManifestByPage.htm',
        contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
        columns: [
            {
                title: "序号",
                align: 'center',
                formatter:function(value,row,index){
                    return index + 1;
                }
            },
            {
                title: "货单号",
                field: "manifestNum",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "货单名",
                field: "manifestName",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "路线途经城市",
                field: "roadCrossName",
                align: 'center', 
                valign: 'middle',
                valign: 'middle'
            },
            {
                title: "货车牌号",
                field: "truckCarNum",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "司机姓名",
                field: "driverName",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "开始站点",
                field: "stationStrName",
                align: 'center',
                valign: 'middle',
                valign: 'middle'
            },
            {
                title: "结束站点",
                field: "stationEndName",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "是否提单",
                field: "manifestIsTake",
                align: 'center',
                formatter: function(value, row, index){
                    var take = "-";
                    if(row.manifestIsTake == 0){
                    	take = '<span style="color:#ed5565;">未提单</span>';
                    }else if(row.manifestIsTake == 1){
                    	take ='<span style="color:#23c6c8;">已提单</span>';
                    }
                    return take;
                }
            },
            {
                title: "回单状态",
                field: "manifestIsReturn",
                align: 'center',
                formatter: function(value, row, index){
                    var me = "-";
                    if(row.manifestIsReturn == 0){
                    	me = '<span style="color:#ed5565;">未回单</span>';
                    }else if(row.manifestIsReturn == 1){
                    	me ='<span style="color:#23c6c8;">已回单</span>';
                    }
                    return me;
                }
            },
            {
            	title: "代收货款总额(元)",
                field: "sumOrderCod",
                align: 'center',
                valign: 'middle'
            },
            {
            	title: "货到付款总额(元)",
                field: "sumOrderForword",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "插入时间",
                field: "manifestInsTime",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "操作",
                align: 'center',
                formatter: function (value, row, index) {
                	var c = '<shiro:hasPermission name="create:order"> <button class="btn btn-xs btn-info" type="button" onclick="manageOrder(\'' + row.manifestId + '\',\'' + row.manifestNum + '\')"><i class="fa fa-edit"></i> 管理订单</button> </shiro:hasPermission>';
                    var e = '<shiro:hasPermission name="create:order"> <button class="btn btn-xs btn-info" type="button" onclick="editManifestInfo(\'' + row.manifestId + '\')"><i class="fa fa-edit"></i> 编辑</button> </shiro:hasPermission>';
                    var d = '';
                    if (row.manifestIsDelete == 0){
                        d = '<shiro:hasPermission name="create:order"> <button class="btn btn-xs btn-danger" type="button" onclick="deleteManifestInfo(\'' + row.manifestId + '\',\'' + row.manifestNum + '\')"><i class="fa fa-trash-o"></i> 删除 </button> </shiro:hasPermission>';
                    }
                    return c + e + d;
                }
            }
        ],
        onLoadSuccess: function(data){
        }
    });
}

//分页参数，条件查询时的参数
function queryParams(queryParamsType){
	var temp = {
		limit: queryParamsType.limit,   //页面大小
		offset: queryParamsType.offset,  //页码
		manifestNum: $.trim($('#manifestNum').val()),
		manifestIsTake: $.trim($('#manifestIsTake').val()),
		manifestIsReturn: $.trim($('#manifestIsReturn').val()),
	};
	return temp;
}

//管理订单
function manageOrder(manifestId, manifestNum){
	var index = layer.open({
        type: 2,
        title: '管理订单',
        maxmin: true,
        shadeClose: false, //点击遮罩关闭层
        area : ['1000px' , '700px'],
        content: '../manifest/manager_order.htm?id='+manifestId + "&num=" + manifestNum,
        success: function(layero, index){
        }
    });
	layer.full(index);
}


//编辑和增加货单
function editManifestInfo(id){
    var title;
    if(id){
        title = '编辑货单';
    }else{
        title = '新增货单';
    }
    layer.open({
        type: 2,
        title: title,
        maxmin: true,
        shadeClose: false, //点击遮罩关闭层
        area : ['500px' , '500px'],
        content: '../manifest/edit_manifest.htm?id='+id,
        success: function(layero, index){
        }
    });
}

//删除货单
function deleteManifestInfo(manifestId, manifestNum) {
    layer.confirm('你确定要删除【' + manifestNum + '】货单吗？', {
        btn: ['确定', '取消'] //按钮
    }, function () {
        $.ajax({
            url: "../manifest/delManifestInfo.htm",
            cache: false,
            type: "post",
            dataType: "json",
            data: {'manifestNum': manifestNum},
            success: function (result) {
                if (result.status == 0) {
                    layer.msg(result.message, {icon: 1});
                    $table.bootstrapTable('refresh', {url: '../manifest/getManifestByPage.htm'});
                    return;
                }
                layer.msg(result.message, {icon: 2});
            }
        });
    }, function () {
    });
}
</script>
</body>
</html>
